package com.gwsdk.paysdk.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.gwsdk.paysdk.acitvityV2.fragment.GWNoticeFragment;
import com.gwsdk.paysdk.bean.NoticeModel;

import java.util.List;


public class GWNoticePagerAdapter extends FragmentPagerAdapter{

    private List<NoticeModel.ListBean> listBeans;
    private GWNoticeFragment noticeFragment;

    public GWNoticePagerAdapter(FragmentManager fm, List<NoticeModel.ListBean> list) {
        super(fm);
        listBeans = list;
    }

    @Override
    public Fragment getItem(int position) {
            noticeFragment = new GWNoticeFragment();
        noticeFragment.setData(listBeans.get(position));
        return noticeFragment;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        GWNoticeFragment o = (GWNoticeFragment)super.instantiateItem(container, position);
        if(o!=null){
            o.setData(listBeans.get(position));
        }
        return o;
    }

    @Override
    public int getCount() {
        return listBeans==null?0:listBeans.size();
    }

    public void setData(List<NoticeModel.ListBean> data) {
        this.listBeans = data;
        notifyDataSetChanged();
    }
}
